﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;


namespace DataEngine.ContractModel
{
    public static class ModelConstants
    {
        public static readonly int INSERT_DATA_SIZE = Marshal.SizeOf(typeof(DATA_POINT));
        public static readonly int PACKET_HEADER_SIZE = Marshal.SizeOf(typeof(PACKET_HEADER));
        public static readonly int REQUEST_HEADER_SIZE = Marshal.SizeOf(typeof(REQUEST_HEADER));
        public static readonly int TAG_HEADER_SIZE = Marshal.SizeOf(typeof(TAG_HEADER));
        public static readonly int H_TLIST_SIZE = Marshal.SizeOf(typeof(H_TLIST));
        public static readonly int TAG_ID_SIZE = sizeof(uint);
    }
    public enum CommandEnum : byte
    {
        INSERT_DATA = 0x01,
        // For Point
        REQUEST_POINT,
        RESPONSE_POINT,
        // For List
        REQUEST_LIST,
        RESPONSE_LIST,
        // For Trend
        REQUEST_TREND,
        RESPONSE_TREND
    }
    public enum QualityEnum :ushort
    {
        QUALITY_BAD =0,
        QUALITY_UNCERTAIN=64,
        QUALITY_GOOD=192,
        QUALITY_CONFIG_ERROR=4,
        QUALITY_NOT_CONNECTED=8,
        QUALITY_DEVICE_FAILURE=12,
        QUALITY_SENSOR_FAILURE=16,
        QUALITY_LAST_KNOWN=20,
        QUALITY_COMM_FAILURE=24,
        QUALITY_OUT_OF_SERVICE=28,
        QUALITY_LAST_USABLE=68,
        QUALITY_SENSOR_CAL=80,
        QUALITY_EGU_EXCEEDED=84,
        QUALITY_SUB_NORMAL=88,
        QUALITY_LOCAL_OVERRIDE=216
    }
    [StructLayout(LayoutKind.Sequential, Pack = 4)]
    public struct DATA_POINT
    {
        public UInt32 TagID;
        public UInt64 TimeStamp;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
        public byte[] Value;
        public UInt16 DataType;
        public byte Quality;
        public byte Reserve;
    }
    [StructLayout(LayoutKind.Sequential, Pack = 4)]
    public struct PACKET_HEADER
    {
        public byte Sign;
        public byte Cmd;
        public UInt16 TrID;
        public UInt32 Length;
    }
    [StructLayout(LayoutKind.Sequential, Pack = 4)]
    public struct REQUEST_HEADER
    {
        public UInt64 endtime;
        public UInt32 duration;
        public UInt32 resolution;
    }
    [StructLayout(LayoutKind.Sequential, Pack = 4)]
    public struct H_TLIST
    {
        public UInt32 TagID;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 96)]
        public string TagName;
        public UInt16 DataType;
        public UInt16 Reserved;
    }
    [StructLayout(LayoutKind.Sequential, Pack = 4)]
    public struct TAG_HEADER
    {
        public UInt32 TagID;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 96)]
        public string TagName;
        public UInt32 DataType;
    }
    public enum RequestType
    {
        PointData,
        ListData,
        TrendData
    }
}
